package com.oocl.File;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.swing.text.StyledEditorKit.ForegroundAction;

import org.junit.Test;

public class FromA_Z {
	@Test
	public  void test1(String[] args) throws IOException {
		OutputStream outputStream=new FileOutputStream("data");
		byte[] buf=new byte[26];
		for(int i=97;i<123;i++)
		{
			buf[i-97]=(byte)i;
		}
		outputStream.write(buf);
		outputStream.close();
	}
	
	@Test
	public void test2() throws Exception
	{
		InputStream inputStream=new FileInputStream("data");
		int m=inputStream.read();
		m=inputStream.read();
		inputStream.skip(1);
		m=inputStream.read();
		System.out.println((char)m);
		inputStream.close();
	}
	@Test
	public void test3() throws Exception
	{
		byte[] buf=new byte[5];
		InputStream inputStream=new FileInputStream("data");
		int count=inputStream.read(buf,0,5);
		System.out.println("count:"+count);
		for(int i=0;i<count;i++)
		{
			System.out.println((char)buf[i]);
		}
		inputStream.close();
	}
	
	@Test
	public void test4() throws Exception
	{
		InputStream inputStream=new FileInputStream(data);
		int m=0;
		while((m=inputStream.read())!=-1)
		System.out.println((char)m);
		
		inputStream.close();
	}
	
	@Test
	public void test5() throws Exception//huancunqu
	{
		InputStream inputStream=new FileInputStream(data);
		byte[] buf=new byte[inputStream.available()];
		inputStream.read(buf);
		System.out.println();
	String string=new String(buf,"utf-8");//可能有乱码问题
	System.out.println(s);//如果文件太大有问题
	inputStream.close();
	}
	
	@Test
	public void test6() throws Exception//huancunqu
	{
		InputStream inputStream=new FileInputStream("data");
		byte[] buf=new byte[2];//2zijie
		int count=0;
		while((count=inputStream.read(buf))!=-1)
		{
			for(int i=0;i<buf.length;i++)//gaiweixunhuandaocount,lengthhuiyou wenti
				System.out.println((char)buf[i]);
		}
		
	inputStream.close();
	}
	

	@Test
	public void test7() throws Exception//huancunqu
	{
		InputStream inputStream=new FileInputStream("data");
		byte[] buf=new byte[2];//2zijie
		int count=0;
		while((count=inputStream.read(buf))!=-1)
		{
			for(int i=0;i<buf.length;i++)//gaiweixunhuandaocount,lengthhuiyou wenti
				System.out.println((char)buf[i]);
		}
		
	inputStream.close();
	}
	
	@Test
	public void test8() throws Exception//huancunqu
	{
		InputStream inputStream=new FileInputStream("data");
		byte[] buf=new byte[2];//2zijie
		int count=0;
		while((count=inputStream.read(buf))!=-1)
		{
			for(int i=0;i<buf.length;i++)//gaiweixunhuandaocount,lengthhuiyou wenti
				System.out.println((char)buf[i]);
		}
		
	inputStream.close();
	}
	@Test
	public void test9() throws Exception
	{
		OutputStream out=new ByteArrayOutputStream(1024);
		out.write("abcd".getBytes());
		out.close();
		ByteArrayOutputStream out1=(ByteArrayOutputStream)out;
		byte[] buf=out1.toByteArray();
		InputStream inputStream=new ByteArrayInputStream(buf);
		int m=inputStream.read();
		System.out.println(m);
		inputStream.close();
	}
	
	}
	
